package com.example.myapplication.widget;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.myapplication.R;

import java.util.Calendar;

public class DialogActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tvAlertResult;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_dialog);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        findViewById(R.id.btn_alert).setOnClickListener(this);
        tvAlertResult = findViewById(R.id.tv_alert_result);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_alert) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            // 设置对话框的标题
            builder.setTitle("尊敬的用户");
            // 设置对话框的文本内容
            builder.setMessage("你真的要卸载我吗？");
            // 设置对话框的肯定按钮（相当于选择“确定”）及其点击监听事件
            builder.setPositiveButton("残忍卸载", ((dialog, which) -> {
                tvAlertResult.setText("虽然依依不舍，但是只能离开了。");
            }));
            // 设置对话框的否定按钮（相当于选择“取消”）及其点击监听事件
            builder.setNegativeButton("我再想想", ((dialog, which) -> {
                tvAlertResult.setText("让我再陪你三百六十五个日夜。");
            }));
            // 创建对话框
            AlertDialog dialog = builder.create();
            // 显示对话框
            dialog.show();
        }
    }

}